package com.hlhj.carview.aty

import android.support.v7.widget.LinearLayoutManager
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Iview.GainView
import com.hlhj.carview.R
import com.hlhj.carview.adapter.GainListAdp
import com.hlhj.carview.bean.GainDetailBean
import com.hlhj.carview.presenter.GainPresenter
import com.liaoinstan.springview.container.DefaultFooter
import com.liaoinstan.springview.container.DefaultHeader
import com.liaoinstan.springview.widget.SpringView
import kotlinx.android.synthetic.main.lo_list.*

/**
 * Created by Never Fear   on 2018\12\20 0020.
Never More....
 */
class GainAty :BaseAty<GainView,GainPresenter>(), GainView {
    private var adp:GainListAdp?=null
    private val datas=ArrayList<GainDetailBean.InfoBean.DataBean>()
    private var page=1
    override fun setGain(gainDetailBean: GainDetailBean) {
        if (page==1){
            datas.clear()
        }
        spView?.onFinishFreshAndLoad()
        datas.addAll(gainDetailBean.info.data)
        adp?.notifyDataSetChanged()
    }

    override fun initView() {
        adp= GainListAdp(datas)

        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        listView.adapter=adp

        spView?.header=DefaultHeader(this)
        spView?.footer=DefaultFooter(this)

    }

    override fun logicStart() {
        presenter?.getGain(page,this)
    }

    override fun setListener() {
        spView?.setListener(object :SpringView.OnFreshListener{
            override fun onLoadmore() {
                page++
                presenter?.getGain(page,this@GainAty)
            }

            override fun onRefresh() {
                page=1
                presenter?.getGain(page,this@GainAty)
            }
        })
    }

    override fun bindView(): GainView {
        return this
    }
    override fun createPresenter(): GainPresenter {
        return GainPresenter()
    }
    override fun getContentID(): Int {
        return R.layout.aty_gain
    }
}